home *** CD-ROM | disk | FTP | other *** search
/ Enter 2003 July / EnterCD 7_2003.iso / Ekstra / GL Force 2001 3.0 / Camera.h < prev    next >
Encoding:
C/C++ Source or Header  |  2001-12-16  |  3.3 KB  |  166 lines

  1. #ifndef CAMERA_H
  2. #define CAMERA_H
  3.  
  4. #include <math.h>
  5.  
  6. #define PI 3.14159
  7.  
  8.  
  9. class Camera
  10. {
  11.     private:
  12.         GLfloat x, y, z;
  13.         float angle; //radians
  14.         float radius;
  15.         BOOL radiusLimiter;
  16.         BOOL heightLimiter;
  17.         float maxRadius, minRadius;
  18.         float maxHeight, minHeight;
  19.  
  20.     public:
  21.         // angle in radians
  22.         // positive z axis coming out of the screen
  23.         Camera(GLfloat ang, GLint rad, GLint yy)
  24.         {
  25.             heightLimiter = FALSE;
  26.             radiusLimiter = FALSE;
  27.             maxHeight = 200.0f;
  28.             minHeight = -100.0f;
  29.             maxRadius = 300.0f;
  30.             minRadius = 12;
  31.             angle = ang;
  32.             radius = (float) rad;
  33.             y = yy;
  34.             x=static_cast<GLfloat>(radius*cos(angle)+12.0f);
  35.             z=static_cast<GLfloat>(radius*sin(angle)-12.0f);
  36.         }
  37.  
  38.         ~Camera() {}
  39.  
  40.         void SetCamera(GLfloat ang, GLint rad, GLint yy)
  41.         {
  42.             angle = ang;
  43.             radius = rad;
  44.             x=static_cast<GLfloat>(radius*cos(angle)+12.0f);
  45.             z=static_cast<GLfloat>(radius*sin(angle)-12.0f);
  46.             y = yy;
  47.         }
  48.  
  49.         GLfloat getX() {return x;}
  50.         GLfloat getY() {return y;}
  51.         GLfloat getZ() {return z;}
  52.         void Up()
  53.         {
  54.             //dont let the camera get higher than maxHeight
  55.             //if it does, then move it back down
  56.             //until it gets all the way to minHeight
  57.             if(y <= maxHeight && !heightLimiter)
  58.             {
  59.                 if(y >= maxHeight)
  60.                     heightLimiter = TRUE;
  61.  
  62.                 y += 1.0f;                
  63.             }
  64.             else
  65.             {
  66.                 if(y <= minHeight)
  67.                     heightLimiter = FALSE;
  68.  
  69.                 y -= 1.0f;
  70.             }
  71.         }
  72.  
  73.         void Down()
  74.         {
  75.             //don't let the camera get lower than minHeight
  76.             //ifit does, then begin increasing it until it gets to maxHeight
  77.             if(y >= minHeight && !heightLimiter)
  78.             {
  79.                 if(y <= minHeight)
  80.                     heightLimiter = TRUE;
  81.  
  82.                 y -= 1.0f;
  83.             }
  84.             else
  85.             {
  86.                 if(y >= maxHeight)
  87.                     heightLimiter = FALSE;
  88.  
  89.                 y += 1.0f;
  90.             }
  91.         }
  92.  
  93.         void RotateC()
  94.         {
  95.             //keep the angle between 360 and -360
  96.             if(angle < -360)
  97.                 angle += 360;
  98.  
  99.             angle -= 0.1f;
  100.             x=static_cast<GLfloat>(radius*cos(angle)+12.0f);
  101.             z=static_cast<GLfloat>(radius*sin(angle)-12.0f);
  102.         }
  103.  
  104.         void RotateCC()
  105.         {
  106.             //keep the angle between 360 and -360
  107.             if(angle > 360)
  108.                 angle -= 360;
  109.  
  110.             angle += 0.1;
  111.             x=static_cast<GLfloat>(radius*cos(angle)+12.0f);
  112.             z=static_cast<GLfloat>(radius*sin(angle)-12.0f);
  113.         }
  114.  
  115.         void In()
  116.         {
  117.             //don't let the camera get closer to the y than minRadius
  118.             //if the radius gets down to 12, then increase it
  119.             //until it gets to the maximum radius
  120.             if(radius >= minRadius && !radiusLimiter)
  121.             {
  122.                 if(radius <= minRadius)
  123.                     radiusLimiter = TRUE;
  124.  
  125.                 radius -= 1.0f;
  126.             }
  127.             else
  128.             {
  129.                 if(radius >= maxRadius)
  130.                     radiusLimiter = FALSE;
  131.                 radius += 1.0f;
  132.  
  133.             }
  134.  
  135.             x=static_cast<GLfloat>(radius*cos(angle)+12.0f);
  136.             z=static_cast<GLfloat>(radius*sin(angle)-12.0f);                
  137.         }
  138.  
  139.         void Out()
  140.         {
  141.             //dont let the camera go further than maxRadius away from the y axis
  142.             //if it gets out to a radius of 100, then move it back in
  143.             //until it gets all the way back in to the minimum radius
  144.             if(radius <= maxRadius && !radiusLimiter)
  145.             {
  146.                 if(radius >= maxRadius)
  147.                     radiusLimiter = TRUE;
  148.  
  149.                 radius += 1.0f;                
  150.             }
  151.             else
  152.             {
  153.                 if(radius <= minRadius)
  154.                     radiusLimiter = FALSE;
  155.  
  156.                 radius -= 1.0f;
  157.             }
  158.  
  159.             x=static_cast<GLfloat>(radius*cos(angle)+12.0f);
  160.             z=static_cast<GLfloat>(radius*sin(angle)-12.0f);                
  161.         }
  162. };
  163.  
  164.  
  165.  
  166. #endif